﻿using Microsoft.AspNetCore.Mvc;
using Zhaoxi.NET6.Interfaces;

namespace NET6Demo.WebApi.Controllers
{
    /// <summary>
    /// 模型绑定
    /// </summary>
    [ApiController]
    [ApiVersion("1.0")]
    [Route("[controller]/v{version:apiVersion}")]
    public class IOCContainerController : ControllerBase
    {
        private readonly ILogger<IOCContainerController> _logger;
        private readonly ITestServiceA _ITestServiceA;
        private readonly ITestServiceB _ITestServiceB;
        private readonly IServiceProvider _IServiceProvider;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="iTestServiceA"></param>
        /// <param name="iTestServiceB"></param>
        /// <param name="iServiceProvider"></param>
        public IOCContainerController(ILogger<IOCContainerController> logger, ITestServiceA iTestServiceA, ITestServiceB iTestServiceB, IServiceProvider iServiceProvider)
        {
            _logger = logger;
            _ITestServiceA = iTestServiceA;
            _ITestServiceB = iTestServiceB;
            _IServiceProvider = iServiceProvider;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet()]
        public string ShowA([FromServices] ITestServiceB iTestServiceBNew, [FromServices] IServiceProvider iServiceProvider)
        {
            ITestServiceB testServiceB1 = _IServiceProvider.GetService<ITestServiceB>()!;
            ITestServiceB testServiceB2 = iServiceProvider.GetService<ITestServiceB>()!;
            return _ITestServiceA.ShowA();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost()]
        public string ShowB()
        {
            return _ITestServiceB.ShowB();
        }
    }
}
